package com.xxl.job.executor.utils;

import java.util.Random;
import java.util.UUID;


/**
 * 主键生成
 *
 * @Auther: Ace Lee
 * @Date: 2019/3/11 16:05
 */
public class MyIdGenerator {


    /**
     * 生成大写UUID
     *
     * @return
     */
    public static String getNextId() {
        String uuid = generateId().toString().toUpperCase();
        return uuid;
    }

    public static UUID generateId() {
        return UUID.randomUUID();
    }

    /**
     * 获取自动生成的UUID字符串
     *
     * @return
     */
    public static String generateUUID() {
        UUID uuid = UUID.randomUUID();
        String str = uuid.toString();
        // 去掉"-"符号
        String temp = str.replaceAll("-", "");
        return temp;
    }

    /**
     * 获取一定长度的uuid字符串
     *
     * @param length
     * @return
     */
    public static String generateString(int length) {
        String str = generateUUID();
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(str.charAt(random.nextInt(str.length())));
        }
        return sb.toString();
    }

}